package math.probability;

import java.util.ArrayList;
import java.util.Random;

public class WeibullDistribution extends ProbDistribution {
	private Double l;
	private int k;

	
	public WeibullDistribution(int k, Double l) {
		this.k = k;
		this.l = l;
	}
	
	public WeibullDistribution() {
		this(1,1.0);
	}
	
	
	public ArrayList<Double> getSample(int n) {
		Random r = new Random();
		ArrayList<Double> sample = new ArrayList<Double>();
		for (int i = 0; i < n; i++) {
			sample.add(Math.pow(-Math.log(r.nextDouble()),1.0/k)*l);
		}
		return sample;
	}
	
	public ArrayList<Double> getSample(int n, Random r) {
		ArrayList<Double> sample = new ArrayList<Double>();
		for (int i = 0; i < n; i++) {
			sample.add(Math.pow(-Math.log(r.nextDouble()),1.0/k)*l);
		}
		return sample;
	}
	
	public String toString() {
		return "W(" + String.format("%2.2f", l) + ")";
		 
	}

	@Override
	public Double getNext() {
		Random r = new Random();
		return Math.pow(-Math.log(r.nextDouble()),1.0/k)*l;
	}
	
	public Double getNext(Random r) {
		return Math.pow(-Math.log(r.nextDouble()),1.0/k)*l;
	}
	
	public Double getDisp() {
		return 1/(l*l);
	}
}
